from pdbc_p.pdbc import db_queryall, db_queryone, db_operation
from utinity_p.utinity import check_number


def salesreport():
    result=db_queryall("select * from buycar where order_status='off'")
    for item in result:
        for i in item:
            print(i,end="\t")
        print("")
# 扩展：加上时间，更详细的筛选

def book_import():
    bookname=input("输入书名：")
    author=input("作者：")
    press=input("出版商：")
    purchase_price=input("进货价格：")
    sales_price = input("销售价格：")
    amount = input("数量：")
    if check_number(purchase_price) and check_number(sales_price) and check_number(amount):
    #     入库的判断书名是否存在，存在而且其他信息(出版商，)一样，添加数量；如果书名不存在，直接添加
        result=db_queryone("select bookname,author,press,purchase_price from libary where bookname='%s'"%bookname)
        if result!=None:
#            对比其他信息
            if result[1]!=author or result[2]!=press or result[3]!=purchase_price:
                db_operation("insert into libary values ('%s','%s','%s',%f,%f,%d)" % (
                bookname, author, press, purchase_price, sales_price, amount))
                print("图书入库成功")
            else:
                db_operation("update libary set amount=amount+%d where bookname='%s'"%(int(amount),bookname))
        else:
            db_operation("insert into libary values ('%s','%s','%s',%f,%f,%d)"%(bookname,author,press,purchase_price,sales_price,amount))
            print("图书入库成功")




